package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.fixtureTechConditionPojo;
import com.example.pojo.measuringToolChecklistPojo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface fixtureTechConditionMapp {
    @DS("newMscLowCodeFormal")
    @Insert("insert into ddm_fixture_tech_condition(" +
            "id, create_time, update_time, " +
            "creator, process_status, sys_update_user, " +
            "sys_audit_user, sys_audit_time, sys_deleted, " +
            "equipment_name, equipment_name_english, equipment_name_russian, " +
            "equipment_model, category, category_english, " +
            "category_russian, fixture_name, fixture_name_english, " +
            "fixture_name_russian, drawing_number, engine_model, " +
            "control_project, control_project_english, control_project_russian, " +
            "measurement_technique, measurement_technique_english, measurement_technique_russian, " +
            "measurement_type, standard_value, upper_tolerance, " +
            "lower_tolerance, capacity, frequency, " +
            "control_method, control_method_english, control_method_russian, " +
            "department, source, fixture_list_id)" +
            "VALUES(" +
            "#{id}, #{create_time}, #{update_time}, " +
            "#{creator}, #{process_status}, #{sys_update_user}, " +
            "#{sys_audit_user}, #{sys_audit_time}, #{sys_deleted}, " +
            "#{equipment_name}, #{equipment_name_english}, #{equipment_name_russian}, " +
            "#{equipment_model}, #{category}, #{category_english}, " +
            "#{category_russian}, #{fixture_name}, #{fixture_name_english}, " +
            "#{fixture_name_russian}, #{drawing_number}, #{engine_model}, " +
            "#{control_project}, #{control_project_english}, #{control_project_russian}, " +
            "#{measurement_technique}, #{measurement_technique_english}, #{measurement_technique_russian}, " +
            "#{measurement_type}, #{standard_value}, #{upper_tolerance}, " +
            "#{lower_tolerance}, #{capacity}, #{frequency}, " +
            "#{control_method}, #{control_method_english}, #{control_method_russian}, " +
            "#{department}, #{source}, #{fixture_list_id})")
    //声明insertOne方法不返回任何值
    void insertOne(fixtureTechConditionPojo pojo);

    // 根据部门查询工装技术条件数据
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_fixture_tech_condition where sys_deleted=0 and department = #{department}")
    List<fixtureTechConditionPojo> queryByDepartment(String department);

    //根据ID，选择一行数据
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_fixture_tech_condition where id=#{id}")
    fixtureTechConditionPojo selectById(String id);

    //根据IdUse编辑某一行数据
    //指定数据库
    @DS("newMscLowCodeFormal")
    //更新哪些字段的数据
    @Update("update ddm_fixture_tech_condition " +
            "set " +
            "id=#{id}, " +
            "create_time=#{create_time}, " +
            "update_time=#{update_time}, " +
            "creator=#{creator}, " +
            "process_status=#{process_status}, " +
            "sys_update_user=#{sys_update_user}, "+
            "sys_audit_user=#{sys_audit_user}, " +
            "sys_audit_time=#{sys_audit_time}, " +
            "sys_deleted=#{sys_deleted}, " +
            "equipment_name=#{equipment_name}, " +
            "equipment_name_english=#{equipment_name_english}, " +
            "equipment_name_russian=#{equipment_name_russian}, " +
            "equipment_model=#{equipment_model}, " +
            "category=#{category}, " +
            "category_english=#{category_english}, " +
            "category_russian=#{category_russian}, " +
            "fixture_name=#{fixture_name}, " +
            "fixture_name_english=#{fixture_name_english}, " +
            "fixture_name_russian=#{fixture_name_russian}, " +
            "drawing_number=#{drawing_number}, " +
            "engine_model=#{engine_model}, " +
            "control_project=#{control_project}, " +
            "control_project_english=#{control_project_english}, " +
            "control_project_russian=#{control_project_russian}, " +
            "measurement_technique=#{measurement_technique}, " +
            "measurement_technique_english=#{measurement_technique_english}, " +
            "measurement_technique_russian=#{measurement_technique_russian}, " +
            "measurement_type=#{measurement_type}, " +
            "standard_value=#{standard_value}, " +
            "upper_tolerance=#{upper_tolerance}, " +
            "lower_tolerance=#{lower_tolerance}, " +
            "capacity=#{capacity}, " +
            "frequency=#{frequency}, " +
            "control_method=#{control_method}, " +
            "control_method_english=#{control_method_english}, " +
            "control_method_russian=#{control_method_russian}, " +
            "department=#{department}, " +
            "source=#{source} " +
            "where id=#{id}")
    void editOneByIdUse(fixtureTechConditionPojo pojo);

    //查询某一字段为某值的数据
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_fixture_tech_condition " +
            "where sys_deleted=0 and ${fieldName}=#{fieldValue}")
    List<fixtureTechConditionPojo> queryOneField(String fieldName, String fieldValue);

    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_fixture_tech_condition " +
            "where sys_deleted=0 and ${fieldName1}=#{fieldValue1} and ${fieldName2}=#{fieldValue2}")
    List<fixtureTechConditionPojo> queryTwoFields(String fieldName1, String fieldValue1, String fieldName2, String fieldValue2);

    //删除工装技术条件表中fieldName中为fieldVal的数据
    @DS("newMscLowCodeFormal")
    @Delete("delete from ddm_fixture_tech_condition where ${fieldName}=#{fieldVal}")
    void deleteOneField(String fieldName, String fieldVal);

    //分页查询工装技术条件
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_fixture_tech_condition where " +
            "department=#{department} and sys_deleted=0 " +
            "order by drawing_number ASC " +
            "limit #{startRow}, #{size}")
    List<fixtureTechConditionPojo> queryByPage(Integer startRow, Integer size, String department);

    //查询所有工装技术条件条数
    @DS("newMscLowCodeFormal")
    @Select("SELECT COUNT(*) FROM ddm_fixture_tech_condition where department=#{department} and sys_deleted=0")
    Integer queryQuantity(String department);

    //查询所有工装技术条件中不重复的图号
    @DS("newMscLowCodeFormal")
    @Select("SELECT * FROM ddm_fixture_tech_condition t1 " +
            "WHERE t1.id = (" +
            "  SELECT MIN(t2.id) FROM ddm_fixture_tech_condition t2 " +
            "  WHERE t2.drawing_number = t1.drawing_number" +
            ")")
    List<fixtureTechConditionPojo> queryDrawingNumber();
}
